/**
 * Copyright (C) 2018 - 2020 https://github.com/LeeYan9
 * <p>
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 * <p>
 * http://www.apache.org/licenses/LICENSE-2.0
 * <p>
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package com.bifrost.task;

import com.bifrost.service.SapDataSyncService;
import com.xxl.job.core.biz.model.ReturnT;
import com.xxl.job.core.handler.IJobHandler;
import com.xxl.job.core.handler.annotation.JobHandler;
import com.xxl.job.core.log.XxlJobLogger;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

/**
 * @author Lee
 * Create Class on 2018/11/2
 * @com.bifrost.task
 * @wechat-mall
 */
@Component
@JobHandler("sapDataSyncTask")
public class SapDataSyncTask extends IJobHandler{

    @Autowired
    SapDataSyncService sapDataSyncService;


    @Override
    /**
     * 同步Sap相关数据
     */
    public ReturnT<String> execute(String param) throws Exception {

        if(StringUtils.isBlank(param)){
            return ReturnT.SUCCESS;
        }
        switch (param){
            case "syncSapGoods":
                XxlJobLogger.log("同步商品开始");
                sapDataSyncService.syncSapGoods();
                XxlJobLogger.log("同步商品完成");
                break;
            case "synSapContract":
                XxlJobLogger.log("同步合同开始");
                sapDataSyncService.synSapContract();
                XxlJobLogger.log("同步合同完成");
                break;
                default:break;
        }
        return ReturnT.SUCCESS;
    }
}
